import java.util.Iterator;
import java.util.List;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import friendShips.User;

@Path("/findFriend/{username}")

public class Friends {
	    @GET
	    @Produces("text/html")
	    public String getUser(@PathParam("username") String userName) 
	  {
	    	
			 User user = new User();
			 SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
			 Session session = sessionFactory.openSession();
			 UserManager manager = new UserManager(session); 
			 Query query = session.createQuery("from User user where user.email = :newEmail");
			 query.setParameter("newEmail", userName);
			 //query.setParameter("newPassword", password);
			 List <User>list = query.list();
			 Iterator<User> it=list.iterator();
			 user=it.next();
			 
			if (list.size()==0 || user.isOnline()==false)
				return "BAD";

		    // String temp=user.getLocation();
			 return user.getLocation();
	    }
}
